|
|
|
|
|
|
|
form for the CompanyMaster database project you started last week. When you finish today's exercises, you'll be able to build a fully functional data entry form with less than 30 lines of Visual Basic code. |
|
|
|
|
|
|
|
|
Why Use Code Instead of the Data Control? |
|
|
|
|
|
|
|
|
Before jumping into the code routines, you should know the difference between writing data entry programs with the Visual Basic data control and writing them without the Visual Basic data control. There are advantages and disadvantages to each method. |
|
|
|
|
|
|
|
|
The advantage of using the data control is that you can quickly put together solid data entry forms without writing much Visual Basic code. This method works well for small, one-time projects that need to be completed quickly. The disadvantage of using the data control is that once the project is completed, it is not always easy to modify the data entry form or adapt the finished form for another data entry project. Also, forms built using the data control are not always easy to debug or maintain because most of the action goes on in the data control itself. If you think your project needs to be modified or maintained by other programmers, the data control might not be your best choice. |
|
|
|
|
|
|
|
|
The advantage of using complete Visual Basic code to produce data entry forms is that you have total control over all aspects of the process. You decide when to open the database and Recordset, and you control the record read and write operations, too. This capability can be a real advantage in multiuser settings where increased traffic can cause locking conflicts in programs that use the data control. Another advantage of using Visual Basic code for your data entry forms is that you can create generic code that you can reuse in all your database projects. When you have a fully debugged set of data entry routines, you can quickly create new forms without much additional coding. Because the forms rely on generic routines, they are also easy to modify and maintain in the future. |
|
|
|
|
|
|
|
|
The primary drawback for using Visual Basic code to create data entry forms is that you have to handle all processes yourself; you can assume nothing. For example, locating and updating a single record in a data table requires that you account for all of the following processes: |
|
|
|
|
|
|
|
|
· Locating the requested record |
|
|
|
|
|
|
|
|
· Loading the input controls from the Recordset |
|
|
|
|
|
|
|
|
· Handling all user actions during the data entry process |
|
|
|
|
|
|
|
|
· Writing the updated controls back to the Recordset |
|
|
|
|
|